package com.admin.kotlintest.activity.setting

import android.content.Intent
import android.os.Bundle
import android.webkit.WebView
import cn.bmob.v3.BmobQuery
import cn.bmob.v3.BmobUser
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import com.admin.kotlintest.R
import com.admin.kotlintest.adapter.UserListAdapter
import com.admin.kotlintest.base.BaseActivity
import com.admin.kotlintest.bean.MyUser
import com.socks.library.KLog
import kotlinx.android.synthetic.main.activity_user_manager.*
import kotlinx.android.synthetic.main.layout_title.*
import org.jetbrains.anko.startActivity
import java.io.Serializable

/**
 * Created by 吴昶 on 2018/4/13.
 */
class UserManagerActivity:BaseActivity(){

    var userListAdapter:UserListAdapter?=null

    override fun bindLayout(): Int {
        return R.layout.activity_user_manager
    }

    override fun initData() {
        tv_title.text="用户列表"
        userListAdapter= UserListAdapter(this,R.layout.layout_list_user_item, null)
        lv_user_list.adapter=userListAdapter
        var user=BmobUser.getCurrentUser(MyUser::class.java)
        var userQuery=BmobQuery<MyUser>()
        userQuery.addWhereNotEqualTo("objectId",user.objectId)
        userQuery.findObjects(object :FindListener<MyUser>(){
            override fun done(p0: MutableList<MyUser>?, p1: BmobException?) {
                p1?:let {
                    p0?.let {
                        userListAdapter!!.upData(p0)
                    }
                }
                p1?.let {
                    KLog.d(p1.message)
                }
            }
        })
    }

    override fun initEvent() {
        lv_user_list.setOnItemClickListener { parent, view, position, id ->
            var user=userListAdapter!!.getItem(position) as Serializable
            var intent=Intent(this,UserSettingActivity::class.java)
            var bundle=Bundle()
            bundle.putSerializable("user",user)
            intent.putExtras(bundle)
            startActivity(intent)
        }
    }
}